var app = getApp();
import { credit } from "../../../../js/modules/credit.js";
import { orderPay } from "../../../../js/modules/pay.js";
import { forms, storage, util, dialog,api} from '../../../../js/util';
import {
  router
} from '../../../../js/router';
import { config } from "../../../../js/modules/gloab.js";
import authorize from '../../../../js/modules/authorize.js'
import BasePage from '../../../../js/common/base-page'
BasePage({
  pageKey:"billPayComfirm",

  /**
   * 页面的初始数据
   */
  data: {
    repayInfo:{},
    repayId:0,
    billId:0,
    invalidMinutes:15,
    Currency:'',//货币符号
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //判断是否登录
    if (!authorize.isLogin('store')) {
      authorize.redirect('store');
      return;
    }
    this.data.repayId = options.repayId||0;
    this.data.billId=options.billId||0;
    if (this.data.billId==0){
      util.tips("请求无效");
      return;
    }

    var that=this;
    that.setData({
      billId: this.data.billId,
      repayId: this.data.repayId
    });
    this.get_repay_info();
    this.getWholesaleConfig();
  }, 
  /**
   * 按账单还款
   */
  get_repay_info:function(){
    var that=this;
    credit.get_repay_info(this.data.repayId, this.data.billId, function(content){
     that.setData({
       repayId:content.Id,
       repayInfo:content
     });
    });
  },

  /**加载还款支付有效分钟数参数 */
  getWholesaleConfig() {
    var that = this;
    var fkid = app.dns.proprietorId;
    var fkflag = app.dns.proprietor;
    config.getWholesaleConfigs(
      fkid,
      fkflag,
      "Wholesale",
      (model) => {
        that.setData({
          invalidMinutes: model.InvalidMinutes
        });
      });
  },
  /**
   * 跳转到收营台
   */
  onCashierEvent(){
    var that = this;
    orderPay.findPayOrderData(that.data.repayInfo.PaySign, "cashier");
  },
  /**
   * 取消
   */
  onCancelRepayEvent(){
    var that=this;
    credit.cancelRepay(this.data.repayId,function(){
      router.redirect({
        path:"billList"
      })
    });
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      Currency:api.Currency || '￥'
    })
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})